﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ChinaDynastyTours.Helpers;
using DevExpress.XtraBars;
using System.Threading;
using System.Configuration;
using ChinaDynastyTours.Controls;
using System.Web.Security;

namespace ChinaDynastyTours.Views
{
    public partial class MainForm : DevExpress.XtraEditors.XtraForm
    {
        //string skinMask = "Skin:";
        
        //空闲时间打开控制台

        public MainForm()
        {
            InitializeComponent();
           
            //string themeName = ConfigurationManager.AppSettings["Themes"];
            
            this.Visible = false;
            //foreach (DevExpress.Skins.SkinContainer cnt in DevExpress.Skins.SkinManager.Default.Skins)
            //{
            //    BarButtonItem item = new BarButtonItem(MainBarManager, skinMask + cnt.SkinName);
            //    iPaintStyle.AddItem(item);
            //    item.ItemClick += new ItemClickEventHandler(OnSkinClick);
            //}
            ////显式设定的Theme
            //foreach (BarItemLink item in iPaintStyle.ItemLinks)
            //    if (item.Caption == (skinMask + themeName))
            //        DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(themeName);

            //iPaintStyle.Caption = skinMask + MainLookAndFeel.LookAndFeel.ActiveLookAndFeel.SkinName;
        }
        //void OnSkinClick(object sender, ItemClickEventArgs e)
        //{
        //    string skinName = e.Item.Caption.Replace(skinMask, "");
        //    DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(skinName);
        //    MainBarManager.GetController().PaintStyleName = "Skin";
        //    iPaintStyle.Caption = e.Item.Caption;
        //    iPaintStyle.Hint = iPaintStyle.Caption;   
        //    iPaintStyle.ImageIndex = -1;
        
        //    //保存设定
        //    System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        //    config.AppSettings.Settings["Themes"].Value = skinName;
        //    config.Save(ConfigurationSaveMode.Modified);
        //}
       private void ChangePwdButtonItem_ItemClick(object sender, ItemClickEventArgs e)
        {
            ChangePasswordForm uw = new ChangePasswordForm(Thread.CurrentPrincipal.Identity.Name, new SecurityHelper());
            if (DialogResult.OK == uw.ShowDialog(this))
            {
                MessageBox.Show("此用户信息修改成功", "信息提示", MessageBoxButtons.OK);
            }
        }

        
        private void AboutButtonItem_ItemClick(object sender, ItemClickEventArgs e)
        {
            new AboutBox().ShowDialog(this);
        }

        private void ExitButtonItem_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (MessageBox.Show("确定退出系统吗？", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                Application.Exit();
        }

        #region 组团管理

        private void TeamLookUpBarItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form.Name == "LookupTeamGroupForm")
                {
                    form.Activate();
                    return;
                }
            }
            LookupTeamGroupForm lookupTeamGroupForm = new LookupTeamGroupForm();
            lookupTeamGroupForm.MdiParent = this;
            lookupTeamGroupForm.Show();
        }

        #endregion

        private void LocalTeamGroupScheduleBarItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form.Name == "LocalTeamGroupForm")
                {
                    form.Activate();
                    return;
                }
            }
            LocalTeamGroupForm localTeamGroupForm = new LocalTeamGroupForm();
            localTeamGroupForm.MdiParent = this;
            localTeamGroupForm.Show();
        }

        private void SeriesTeamManagerBarItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form.Name == "SeriesTeamGroupManagerForm")
                {
                    form.Activate();
                    return;
                }
            }
            SeriesTeamGroupManagerForm seriesTeamGroupManagerForm = new SeriesTeamGroupManagerForm();
            seriesTeamGroupManagerForm.MdiParent = this;
            seriesTeamGroupManagerForm.Show();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            
            if (DialogResult.OK == new LoginWindow(new SecurityHelper()).ShowDialog(this))
            {
                this.Visible = true;
                this.WindowState = FormWindowState.Maximized;
                MainBarManager.Bars[1].ItemLinks[1].Caption = Thread.CurrentPrincipal.Identity.Name;//UserInfoCtrl.GetNameByUserName(Thread.CurrentPrincipal.Identity.Name);
                //string[] providerInfo = BaseInfoCtrl.GetProviderNameAndID(Thread.CurrentPrincipal.Identity.Name);
                MainBarManager.Bars[1].ItemLinks[3].Caption = ApplicationHelper.CurrentLoginProviderNameAndID[0];
            }
            else
                this.Close();
        }

        private void GuideStatusBarItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            //foreach (Form form in Application.OpenForms)
            //{
            //    if (form.Name == "GuideStatusForm")
            //    {
            //        form.Activate();
            //        return;
            //    }
            //}
            //GuideStatusForm guideStatusForm = new GuideStatusForm();
            //guideStatusForm.MdiParent = this;
            //guideStatusForm.Show();
        }

        private void GuidBaseInfoBarItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            //foreach (Form form in Application.OpenForms)
            //{
            //    if (form.Name == "GuideManagerForm")
            //    {
            //        form.Activate();
            //        return;
            //    }
            //}
            //GuideManagerForm guideManagerForm = new GuideManagerForm();
            //guideManagerForm.MdiParent=this;
            //guideManagerForm.Show();
        }

 


        private void GuidNotifiedBarItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            //foreach (Form form in Application.OpenForms)
            //{
            //    if (form.Name == "GuideNotifiedForm")
            //    {
            //        form.Activate();
            //        return;
            //    }
            //}
            //GuideNotifiedForm guideNofiedForm = new GuideNotifiedForm();
            //guideNofiedForm.MdiParent = this;
            //guideNofiedForm.Show();
        }


    }
}
